import { SET_LIST, ADD_MESS_ITEM, ADD_CAR_ITEM, SUB_CAR_ITEM, DELETE_CAR_ITEM, SWITCH_CAR_ITEM_CHECK } from './actionsType'
import { getList } from '../api'

export function actionGetList() {
	// 异步action 需要 redux-thunk支持
	return async dispatch => {
		const resp = await getList()
		dispatch({ type: SET_LIST, payload: resp.data.data })
	}
}
// 添加评论
export function actionAddMess(payload) {
	return { type: ADD_MESS_ITEM, payload }
}

// 添加购物车
export function actionAddCar(payload) {
	return { type: ADD_CAR_ITEM, payload }
}

// 减少购物车
export function actionSubCar(payload) {
	return { type: SUB_CAR_ITEM, payload }
}


// 删除购物车
export function actionDeleteCar(payload) {
	return { type: DELETE_CAR_ITEM, payload }
}

// 切换购物车单选选中状态
export function actionSwitchOne(payload) {
	return { type: SWITCH_CAR_ITEM_CHECK, payload }
}